package com.inossem.warehousemanage_tv.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.inossem.warehousemanage_tv.R;
import com.inossem.warehousemanage_tv.bean.MaterialBean;

import java.util.List;

/**
 * Created by es on 2019/4/26.
 */

public class PurchaseAdapter extends BaseAdapter {

    private Context context;
    private List<MaterialBean.MaterielListBean> list;

    public PurchaseAdapter(Context context, List<MaterialBean.MaterielListBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.material_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        MaterialBean.MaterielListBean materialBean = list.get(position); // 获取当前项的Bean实例
        holder.number.setText(String.valueOf(materialBean.getSerial()));
        holder.material_id.setText(materialBean.getMateriel_number());
        holder.material_into.setText(materialBean.getMateriel_description());
        holder.unit.setText(materialBean.getUnit());
        holder.RFID_id.setText(materialBean.getRfid());
        holder.RFID_count.setText(materialBean.getRfid_number());
        holder.material_count.setText(materialBean.getNumber());
        TextView[] tvs = new TextView[]{holder.number, holder.material_count, holder.material_id, holder.material_into, holder.unit, holder.RFID_count, holder.RFID_id};
        for (TextView tv : tvs) {
            int flag = Integer.parseInt(materialBean.getFlag());
            tv.setTextColor(flag > 0 ? context.getResources().getColor(R.color.up_font) : context.getResources().getColor(R.color.base_black));
        }
        return convertView;
    }

    private class ViewHolder {
        private TextView number;
        private TextView material_id;
        private TextView material_into;
        private TextView unit;
        private TextView RFID_id;
        private TextView RFID_count;
        private TextView material_count;

        public ViewHolder(View view) {
            number = view.findViewById(R.id.number);
            material_id = view.findViewById(R.id.material_id);
            material_into = view.findViewById(R.id.material_into);
            unit = view.findViewById(R.id.unit);
            RFID_id = view.findViewById(R.id.RFID_id);
            RFID_count = view.findViewById(R.id.RFID_count);
            material_count = view.findViewById(R.id.material_count);
        }
    }

}
